package br.edu.senac.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.edu.senac.model.Ingrediente;
import br.edu.senac.repository.IngredienteRepository;
import br.edu.senac.repository.impl.IngredienteRepositoryImpl;

@WebServlet("/IngredienteServlet")
public class IngredienteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public IngredienteServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		Ingrediente ingrediente = new Ingrediente(request.getParameter("nome"),
												  request.getParameter("fabricante"),
												  request.getParameter("unidadeMedida"),
												  Integer.parseInt(request.getParameter("quantidade")));
		
		IngredienteRepository repository = new IngredienteRepositoryImpl();
		repository.salvar(ingrediente);
		
		// TODO Redirecionar de volta para o form de cadastro
		
	}

}
